package org.bultreebank.index.schema.management.interfaces;

import java.util.List;
import java.util.Map;

import org.bultreebank.index.schema.management.impl.SearchEngineField;
import org.bultreebank.index.utils.Pair;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

/**
 * Contains methods for contexts and fields manipulation for a 
 * normalized and available in the Index Repository indexing schema
 * document
 * @author Aneliya Tincheva
 *
 */
public interface IndexContextsManager 
{
	public List<Node> getIndexSchemaRootContexts() throws Exception;
	public Map<String, String> getContextFieldIDs(String realContextID);
	/**
	 * Inits the schema document for implementations of the 
	 * IndexContextsManager
	 * @param schemaDoc
	 */
	public void setIndexSchemaDocument(Document schemaDoc);
	/**
	 * Returns the contexts IDs
	 * @param searchIn
	 * @return
	 * @throws Exception
	 */
	public Pair<String, String> getContextIDs(String searchIn) throws Exception;  
	/**
	 * Returns  a list of all the retrievable fields for the global_context
	 * @param indexSchema -  normalized index schema document
	 * @return
	 * @throws Exception
	 */
	public List<String> getGlobalRetrievableFields() throws Exception;
	/**
	 * Returns  a list of all the searchable fields for the global_context
	 * @param indexSchema -  normalized index schema document
	 * @return
	 * @throws Exception
	 */
	public List<String> getGlobalSearchableFields() throws Exception;
	/**
	 * Returns a map containing the internal - user defined context IDs relevance
	 *  (for contexts that contain field elements)
	 * @param indexSchema -  normalized index schema document
	 * @return
	 */
	public Map<String, String> getContextInternalIDsMap();
	/**
	 * Returns the internal context ID for user defined context ID 
	 * @param userDefinedContextID - user defined context ID
	 * @param indexSchemaDoc -  normalized index schema document
	 * @return
	 * @throws Exception
	 */
	public String getRealContextID (String userDefinedContextID) throws Exception;
	/**
	 * Returns a list of all  indexable (have realIndexID attribute)
	 * context elements for a normalized index schema document
	 * @param indexSchema -  normalized index schema document 
	 * @return
	 * @throws Exception
	 */
	public List<Node> getIndexSchemaContexts() throws Exception;
	
	/**
	 * Adds field elements for the metadata fields as global context,
	 * the field elements have no "value" attribute
	 * @param metadataDoc - document containing metadata fields
	 * @param indexSchema -  normalized index schema document
	 * @throws Exception
	 */
	public void addMetadataContextFields(Document metadataDoc) throws Exception;
	
	/**
	 * Returns a Map with the context IDs as keys and the retrievable fields
	 * defined in the index schema document for these fields
	 * @param indexSchema -  normalized index schema document
	 * @return
	 * @throws Exception
	 */
	public Map<String, List<String>> getContextRetrievableFieldsRealIDs() throws Exception;
	
	/**
	 * Returns a Map with the context IDs as keys and the searchable fields
	 * defined in the index schema document for these fields 
	 * @param indexSchema -  normalized index schema document
	 * @return
	 * @throws Exception
	 */
	public Map<String, List<String>> getContextSearchableFieldsRealIDs() throws Exception;
	
	/**
	 * Returns a list of all the global fields
	 * @param indexSchema -  normalized index schema document
	 * @return
	 * @throws Exception
	 */
	public List<SearchEngineField> getGlobalFields() 
		throws Exception;	
	
}
